import request from '@/utils/request'

// 获取所有知识
export const getListApi = params => {
  return request({
    url: '/knowledgeAdmin/zs/list',
    method: 'get',
    params,
  })
}
// 获取所有问题场景
export const getOneLevelApi = () => {
  return request({
    url: '/knowledgeAdmin/zs/list',
    method: 'get',
  })
}
// 添加知识
export const addZsApi = data => {
  return request({
    url: '/knowledgeAdmin/zs/save',
    method: 'post',
    data,
  })
}

// 获取知识详情信息
export const getDetailApi = id => {
  return request({
    url: `/knowledgeAdmin/zs/detail/${id}`,
    method: 'get',
  })
}

// 修改知识
export const updateZsApi = data => {
  return request({
    url: '/knowledgeAdmin/zs/update',
    method: 'put',
    data,
  })
}

// 获取知识信息
export const getZsByIdApi = id => {
  return request({
    url: `/knowledgeAdmin/zs/info/${id}`,
    method: 'get',
  })
}
// 下线知识
export const deleteZsApi = data => {
  return request({
    url: `/knowledgeAdmin/zs/delete`,
    method: 'delete',
    data,
  })
}
// 上线知识
export const effectiveZsApi = data => {
  return request({
    url: `/knowledgeAdmin/zs/effective`,
    method: 'put',
    data,
  })
}

// 审核不通过
export const notPassApi = data =>{
  return request({
    url: `/knowledgeAdmin/zs/notPass`,
    method: 'post',
    data,
  })
}

// 审核不通过知识详情
export const notPassDetailApi = id =>{
  return request({
    url: `/knowledgeAdmin/zs/failDetail/${id}`,
    method: 'get',
  })

}

// 获取我的知识
export const getMyListApi = params => {
  return request({
    url: '/knowledgeAdmin/zs/myKnowledgeList',
    method: 'get',
    params,
  })
}

// 修改并重新审核知识
export const updateAndReExmineZsApi = data => {
  return request({
    url: '/knowledgeAdmin/zs/updateAndReEamine',
    method: 'put',
    data,
  })
}

// 检索知识
export const searchApi = params => {
  return request({
    url: `/knowledgeAdmin/zs/search`,
    method: 'get',
    params
  })
}

/**
 * 下载知识导入模板
 *
 * @returns
 */
export const downloadTemplateApi = ()=> {
  return request({
    url: '/knowledgeAdmin/zs/template',
    method: 'get',
    responseType: 'arraybuffer'
  });
}

/**
 * 导入知识
 *
 * @param file
 */
export function importZSApi(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/knowledgeAdmin/zs/_import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}